import callback from '../function/callback'
import isArrayLike from '../util/isArrayLike'
// eslint-disable-next-line
import keys from '../function/keys'

function every(obj, predicate, context) {
  predicate = callback(predicate, context)

  const keys = !isArrayLike(obj) && keys(obj)
  const length = (keys || obj).length

  for (let i = 0; i < length; ++i) {
    const currentKey = keys ? keys[i] : i
    if (!predicate(obj[currentKey], currentKey, obj)) {
      return false
    }
  }

  return true
}

export default every
